#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n, cin >> m;
    vector<int> queue;
    for (int i = 0; i < m; ++i) {
        string event;
        cin >> event;
        if (event == "I") {
            int x;
            cin >> x;
            queue.push_back(x);//尾插
        } else if (event == "C") {
            int x, y;
            cin >> x; cin >> y;

            auto it = find(queue.begin(), queue.end(), y);
            if (it!= queue.end()) {
                int index_y = it - queue.begin();
                queue.insert(queue.begin() + index_y, x);
            }
        } else if (event == "L") {
            int x;
            cin >> x;
            auto it = find(queue.begin(), queue.end(), x);
            if (it!= queue.end()) {
                queue.erase(it);
            }
        }
    }
    if (queue.empty()) {
        cout << "Bai Ren Zhan" << endl;
    } else {
        for (int i = 0; i < queue.size(); ++i) {
            cout << queue[i] << " ";
        }
        cout << endl;
    }
    return 0;
}
